#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>

using namespace std;

int maxSubarraySumCircular(vector<int>& nums) {
    int n = nums.size();
    vector<int> f(n + 10, 0);
    vector<int> g(n + 10, 0);
    int sum = 0, fmax = INT_MIN, gmin = INT_MAX;
    for (int i = 1; i <= n; ++i)
    {
        int x = nums[i - 1];
        f[i] = max(x, f[i - 1] + x);
        fmax = max(fmax, f[i]);

        g[i] = min(x, g[i - 1] + x);
        gmin = min(gmin, g[i]);

        sum += x;
    }

    return sum == gmin ? fmax : max(sum - gmin, fmax);
}

int main()
{
	return 0;
}